package com.hkbigdata.userprofile.common.dao

/**
 * @author Clown
 */

import com.alibaba.fastjson.JSONObject
import com.hkbigdata.userprofile.common.bean.TagInfo
import com.hkbigdata.userprofile.common.util.MySqlUtil

import java.util

object TagInfoDAO {

  def getTagInfoByTaskId(taskId: String): TagInfo = {
    val tagInfoSql: String =
      s"""select id,tag_code,tag_name,
         | parent_tag_id,tag_type,tag_value_type,
         | tag_value_limit,tag_task_id,tag_comment,
         | create_time
         | from tag_info
         | where tag_task_id=$taskId""".stripMargin
    val tagInfoOpt: Option[TagInfo] =
      MySqlUtil.queryOne(tagInfoSql, classOf[TagInfo], true)
    var tagInfo: TagInfo = null;
    if (tagInfoOpt != None) {
      tagInfo = tagInfoOpt.get
    } else {
      throw new RuntimeException("no tag  for task_id  : " + taskId)
    }
    tagInfo
  }

  def getTaskTagMergeOnTask(): List[TagInfo] = {
    val infoes: List[TagInfo] = MySqlUtil.queryList(s"select tag.* from tag_info tag join task_info task on " +
      s"tag.tag_task_id = task.id where task.task_status = '1'", classOf[TagInfo], true)
    if (infoes == None) {
      throw new RuntimeException("task id not found")
    }
    infoes
  }

}